package com.ruoyi.web.controller.community.electronicCommerce;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.EcFoods;
import com.ruoyi.community.service.ec.IEcFoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社区电商Controller
 * 
 * @author ruoyi
 * @date 2021-08-15
 */
@RestController
@RequestMapping("/e-commerce/foods")
public class EcFoodsController extends BaseController
{
    @Autowired
    private IEcFoodsService ecFoodsService;

    /**
     * 查询社区电商列表
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:foods:list')")
    @GetMapping("/list")
    public TableDataInfo list(EcFoods ecFoods)
    {
        startPage();
//        List<EcFoods> list = ecFoodsService.selectEcFoodsList(ecFoods);
        List<EcFoods> list = ecFoodsService.selectEcFoodsListByRestaurantId(ecFoods.getRestaurantId().longValue());
        return getDataTable(list);
    }

    /**
     * 导出社区电商列表
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:foods:export')")
    @Log(title = "社区电商", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EcFoods ecFoods)
    {
        List<EcFoods> list = ecFoodsService.selectEcFoodsList(ecFoods);
        ExcelUtil<EcFoods> util = new ExcelUtil<EcFoods>(EcFoods.class);
        return util.exportExcel(list, "社区电商数据");
    }

    /**
     * 获取社区电商详细信息
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:foods:query')")
    @GetMapping(value = "/{foodsId}")
    public AjaxResult getInfo(@PathVariable("foodsId") Long foodsId)
    {
        return AjaxResult.success(ecFoodsService.selectEcFoodsById(foodsId));
    }

    /**
     * 新增社区电商
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:foods:add')")
    @Log(title = "社区电商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EcFoods ecFoods)
    {
        return toAjax(ecFoodsService.insertEcFoods(ecFoods));
    }

    /**
     * 修改社区电商
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:foods:edit')")
    @Log(title = "社区电商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EcFoods ecFoods)
    {
        return toAjax(ecFoodsService.updateEcFoods(ecFoods));
    }

    /**
     * 删除社区电商
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:foods:remove')")
    @Log(title = "社区电商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{foodsIds}")
    public AjaxResult remove(@PathVariable Long[] foodsIds)
    {
        return toAjax(ecFoodsService.deleteEcFoodsByIds(foodsIds));
    }
}
